package com.DesignPatten.Decorator;

/**
 * @ClassName DecoratorTest
 * @Date 2021/5/21 8:57
 * @Author 李明杰
 * @Description 装饰器模式
 */
interface Robot {
    void doSomething();
}

class FirstRobot implements Robot {

    public void doSomething() {
        System.out.println("对话");
        System.out.println("唱歌");
    }
}


//可以定义为抽象类，让他的子类实现更多功能
class DecoratorRobot implements Robot {
    Robot robot;

    public DecoratorRobot(Robot robot) {
        this.robot = robot;
    }

    @Override
    public void doSomething() {
        robot.doSomething();
    }

    public void doMoreThing() {
        System.out.println("第二代：AI对话");
    }

}

public class DecoratorTest {
    public static void main(String[] args) {
        DecoratorRobot decoratorRobot = new DecoratorRobot(new FirstRobot());
        decoratorRobot.doSomething();
        System.out.println("第二代");
        decoratorRobot.doMoreThing();
    }

}
